package com.zhongwang.business.module.quoteManage.quoteManageController;

import com.zhongwang.business.base.BaseController;
import com.zhongwang.business.common.JsonResult;
import com.zhongwang.business.gen.entity.User;
import com.zhongwang.business.module.quoteManage.quoteManageDao.QuotationApproveDao;
import com.zhongwang.business.module.quoteManage.quoteManageDao.QuotationMainDao;
import com.zhongwang.business.module.quoteManage.quoteManageDao.QuotationQueryDao;
import com.zhongwang.business.module.quoteManage.quoteManageModel.QuotationMainModel;
import com.zhongwang.business.module.quoteManage.quoteManageService.QuoteApproveService;
import com.zhongwang.business.module.quoteManage.quoteManageService.QuoteQueryService;
import com.zhongwang.business.module.quoteManage.quoteManageService.QuoteTaskService;
import com.zhongwang.business.module.system.log.LogService;
import com.zhongwang.business.module.system.user.UserService;
import com.zhongwang.business.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 报价查询管理
 * @author zcy
 * @time: 2020-11-2
 */

@Controller
@RequestMapping("/quoteManage")
public class QuoteQueryController extends BaseController {
    @Autowired
    private UserService userService;
    @Autowired
    private LogService logService;
    @Autowired
    private QuotationQueryDao quotationQueryDao;
    @Autowired
    private QuoteQueryService quoteQueryService;

    /**
     * 报价完结页面
     * @param
     * @return 页面路径
     */
    @GetMapping("/quotationQuery/page")
    @RequiresPermissions({"quo:compl:view"})
    public String page() {
//        User user = ShiroUtils.getUser();
//        model.addAttribute("sysUserModel", quotationQueryDao.findOrgMinisterByAccount(user.getAccount()));
        return "quoteManage/quotationQuery";
    }

    /**
     * 报价完结列表数据
     * @param query
     * @return
     */
    @ResponseBody
    @PostMapping("/quotationQuery/list")
    public JsonResult quoteQuerylist(QuotationMainModel query){
        startPage();
        List<QuotationMainModel> list = quoteQueryService.findQuotationQueryList(query);
        return jsonResult(list);
    }

    /**
     * 完结报价
     * @param quotationMainModel
     * @return
     */
    @ResponseBody
    @PostMapping("/quotationQuery/complete")
    @RequiresPermissions({"quo:compl:finish"})
    public JsonResult complQtt(QuotationMainModel quotationMainModel){
        return quoteQueryService.complQtt(quotationMainModel);
    }

    /**
     * 反完结报价
     * @param quotationMainModel
     * @return
     */
    @ResponseBody
    @PostMapping("/quotationQuery/reset")
    @RequiresPermissions({"quo:compl:reset"})
    public JsonResult resetQtt(QuotationMainModel quotationMainModel){
        return quoteQueryService.resetQtt(quotationMainModel);
    }
//    /**
//     * 重新报价
//     * @param quotationMainModel
//     * @return
//     */
//    @ResponseBody
//    @PostMapping("/quotationQuery/reQtt")
////    @RequiresPermissions({"quo:comList:confirm"})
//    public JsonResult reQtt(QuotationMainModel quotationMainModel){
//        return jsonResult(quoteQueryService.reQtt(quotationMainModel));
//    }

    /**
     * 报价历史列表数据
//     * @param query
     * @return
     */
//    @ResponseBody
//    @PostMapping("/qttHistory/list")
//    @RequiresPermissions({"quo:queryList:view"})
//    public JsonResult qttHistory(QuotationMainModel query){
//        startPage();
//        List<QuotationMainModel> list = quoteQueryService.findQttHistoryList(query);
//        return jsonResult(list);
//    }

    /**
     * 报价查询页面
     * @param
     * @return 页面路径
     */
    @GetMapping("/quoteSearch/page")
    @RequiresPermissions({"quo:search:view"})
    public String searchPage(Model model) {
        User user = ShiroUtils.getUser();
        model.addAttribute("sysUserModel", quotationQueryDao.findUserInfoByAccount(user.getAccount()));
        return "quoteManage/quotationSearch";
    }

    /**
     * 报价查询列表数据
     * @param query
     * @return
     */
    @ResponseBody
    @PostMapping("/quotationSearch/list")
    public JsonResult quoteSearchlist(QuotationMainModel query){
        startPage();
        List<QuotationMainModel> list = quoteQueryService.findQuoteSearchlist(query);
        return jsonResult(list);
    }
}
